<?php
namespace app\index\controller;
/**
 *  
 */
class Vip extends Common{
    public function _initialize() {
        parent::_initialize();
        
    }
    
    public function index(){
        $opend = check_login();
        $userInfo = db("member")->where(['openid' => $opend])->find();
        
        if(!$userInfo){
            $wechatUserInfo = $this->getUserInfo();
            if($wechatUserInfo['subscribe'] != 1){
                header("Location:" . url('vip/subscribe'));
            }
            
            db("member")->insert([
                'nickname'  => $wechatUserInfo['nickname'],
                'sex'       => $wechatUserInfo['sex'],
                'openid'    => $wechatUserInfo['openid'],
                'headimgurl'=> $wechatUserInfo['headimgurl'],
                'subscribe' => $wechatUserInfo['subscribe'],
                'regtime'   => time(),
                'integral'  => 0,
                'money'     => 0
            ]);
            
            $url = url("vip/reg");
            header("Location:{$url}");
        }
        $this->assign("userInfo" , $userInfo);
        return $this->fetch();
    }

    /**
     *  填写会员手机号码
     */
    public function reg(){
        $openid = cookie("_openid");
        $userInfo = db("member")->where(['openid' => $openid])->find();
        
        $this->assign("userInfo" , $userInfo);
        return $this->fetch();
    }
    
    /**
     *  关注
     */
    public function subscribe(){
        
    }
}